<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工号" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="工号" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['buss:managerPoint:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="managerPointList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工号" align="center" prop="userName"  />
      <el-table-column label="用户名" align="center" prop="nickName"  />
      <el-table-column label="机构号" align="center" prop="orgId"  />
      <el-table-column label="信贷工号" align="center" prop="xdgh"  />
      <!-- <el-table-column label="维护存量客户信息积分" align="center" prop="updatePoint"  /> -->
      <el-table-column label="维护存量客户信息积分" align="center" prop="updatePoint" >
          <template slot-scope="scope">
            <router-link :to="{path:'/point/updatePoint',query: {userName: scope.row.userName}}" class="link-type">
              <span>{{ scope.row.updatePoint }}</span>
            </router-link>
        </template>
      </el-table-column>
      <el-table-column label="新增客户信息积分" align="center" prop="addPoint" >
          <template slot-scope="scope">
            <router-link :to="{path:'/point/addPoint',query: {userName: scope.row.userName}}" class="link-type">
              <span>{{ scope.row.addPoint }}</span>
            </router-link>
        </template>
      </el-table-column>
      <el-table-column label="授信营销积分" align="center" prop="sxPoint" >
          <template slot-scope="scope">
            <router-link :to="{path:'/point/sxPoint',query: {userName: scope.row.userName}}" class="link-type">
              <span>{{ scope.row.sxPoint }}</span>
            </router-link>
        </template>
      </el-table-column>
      <el-table-column label="用信营销积分" align="center" prop="yxPoint" >
          <template slot-scope="scope">
            <router-link :to="{path:'/point/yxPoint',query: {userName: scope.row.userName}}" class="link-type">
              <span>{{ scope.row.yxPoint }}</span>
            </router-link>
        </template>
      </el-table-column>
      <!-- <el-table-column label="产品用信营销积分" align="center" prop="yxPoint"  /> -->
      <!-- <el-table-column label="贷款授信余额净增积分" align="center" prop="htyejzPoint"  /> -->
      <!-- <el-table-column label="用信余额净增积分" align="center" prop="dkyejzPoint"  /> -->
      <el-table-column label="积分合计" align="center" prop="point"   />
      <el-table-column label="数据日期" align="center" prop="sjrq"  />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改第一阶段网格化营销活动方案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listManagerPoint, getManagerPoint, delManagerPoint, addManagerPoint, updateManagerPoint } from "@/api/buss/managerPoint";

export default {
  name: "ManagerPoint",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 第一阶段网格化营销活动方案表格数据
      managerPointList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 工号字典
      userNameOptions: [],
      // 用户名字典
      nickNameOptions: [],
      // 机构号字典
      orgIdOptions: [],
      // 信贷工号字典
      xdghOptions: [],
      // 维护存量客户信息积分字典
      updatePointOptions: [],
      // 新增客户信息积分字典
      addPointOptions: [],
      // 产品授信营销积分字典
      sxPointOptions: [],
      // 产品用信营销积分字典
      yxPointOptions: [],
      // 贷款授信余额净增积分字典
      htyejzPointOptions: [],
      // 用信余额净增积分字典
      dkyejzPointOptions: [],
      // 积分合计字典
      pointOptions: [],
      // 数据日期字典
      sjrqOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        nickName: null,
        orgId: null,
        xdgh: null,
        updatePoint: null,
        addPoint: null,
        sxPoint: null,
        yxPoint: null,
        htyejzPoint: null,
        dkyejzPoint: null,
        point: null,
        sjrq: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询第一阶段网格化营销活动方案列表 */
    getList() {
      this.loading = true;
      listManagerPoint(this.queryParams).then(response => {
        this.managerPointList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userName: null,
        nickName: null,
        orgId: null,
        xdgh: null,
        updatePoint: null,
        addPoint: null,
        sxPoint: null,
        yxPoint: null,
        htyejzPoint: null,
        dkyejzPoint: null,
        point: null,
        sjrq: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userName)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加第一阶段网格化营销活动方案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userName = row.userName || this.ids
      getManagerPoint(userName).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改第一阶段网格化营销活动方案";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userName != null) {
            updateManagerPoint(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addManagerPoint(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userNames = row.userName || this.ids;
      this.$confirm('是否确认删除第一阶段网格化营销活动方案编号为"' + userNames + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delManagerPoint(userNames);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/managerPoint/export', {
        ...this.queryParams
      }, `buss_managerPoint.xlsx`)
    }
  }
};
</script>
